//
//  PHomeFilterView.m
//  Btpin
//
//  Created by Vic on 2019/12/15.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "PHomeFilterView.h"
#import "LYSegmentView.h"
#import "PHomeFilterAreaView.h"
#import "PHomeFilterBaseInfoView.h"

@interface PHomeFilterView ()<LYSegmentViewDelegate, PHomeFilterAreaViewDelegate, PHomeFilterBaseInfoViewDelegate>
{
    UIScrollView *bottomScrollView;
}
@end

@implementation PHomeFilterView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        self.filterShowFlag = NO;
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    self.backgroundColor = COLOR_OF_WHITE;
    UIView *bgTopView = [UIToolsControl initViewWithFrame:CGRectMake(0, HeightOfStatusBar, WIDTH, 44) backgroundColor:COLOR_OF_WHITE];
    [self addSubview:bgTopView];
    [bgTopView borderColor:THEMECOLOR_OF_Line_Color borderWidth:lineH borderType:BorderSideTypeBottom];
    
    LYSegmentView *segmentView = [[LYSegmentView alloc] initWithFrame:CGRectMake((WIDTH-ScalePS(200))*0.5, 7, 200*Scale, 30)];
        segmentView.delegate = self;
    [segmentView setSegmentWithBackground:[UIColor whiteColor] titleArray:@[@"筛选", @"区域"] titleFont:FontBold(Font_18) titleLineSelectColor:THEMECOLOR_OF_TEXT_333333 normal:THEMECOLOR_OF_TEXT_9a9a9a withselectedIndex:0];
    [segmentView setRightTopLabelWithAry:@[@"0", @"0"]];
    [bgTopView addSubview:segmentView];
    
    UIButton *leftBtn = [UIToolsControl initButtonWithFrame:CGRectMake(10, 0, 44, 44) imageName:@"back_b" target:self action:@selector(dismissView) title:nil titleColor:nil];
//    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(11, 0, 12, 32);
    [bgTopView addSubview:leftBtn];
    
    bottomScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, EndY(bgTopView), WIDTH, HEIGHT-SIMEmojKeyBoardkBottomNOSafeArea_Height-HeightOfStatusBarAndNavigationBar)];
    bottomScrollView.contentSize = CGSizeMake(WIDTH*2, 0);
    bottomScrollView.pagingEnabled = YES;
    bottomScrollView.bounces = NO;
    bottomScrollView.scrollEnabled = NO;
    bottomScrollView.showsHorizontalScrollIndicator = NO;
    bottomScrollView.showsVerticalScrollIndicator = NO;
    [self addSubview:bottomScrollView];
    
    PHomeFilterBaseInfoView *baseInfoView = [[PHomeFilterBaseInfoView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, ViewHeight(bottomScrollView)) target:self];
    [bottomScrollView addSubview:baseInfoView];
    
    PHomeFilterAreaView *areaView = [[PHomeFilterAreaView alloc] initWithFrame:CGRectMake(WIDTH, 0, WIDTH, ViewHeight(bottomScrollView)) target:self];
    [bottomScrollView addSubview:areaView];
}
- (void)showView {
    self.filterShowFlag = YES;
    __weak __typeof(self)weakSelf = self;
    [UIView animateWithDuration:0.3 animations:^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        CGRect frame = strongSelf.frame;
        frame.origin.x = 0;
        strongSelf.frame = frame;
    }];
}
- (void)dismissView {
    self.filterShowFlag = NO;
    __weak __typeof(self)weakSelf = self;
    [UIView animateWithDuration:0.3 animations:^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        CGRect frame = strongSelf.frame;
        frame.origin.x = WIDTH;
        strongSelf.frame = frame;
    }];
}
#pragma mark -- Action
- (void)customSegmentedValueChanged:(UISegmentedControl *)segment{
    NSLog(@"点击button----%ld", segment.selectedSegmentIndex);
    
    bottomScrollView.contentOffset = CGPointMake(WIDTH*segment.selectedSegmentIndex, 0);
}
- (void)pHomeFilterAreaViewOKInfo:(NSDictionary *)dic {
    if (self.delegate && [self.delegate respondsToSelector:@selector(pHomeFilterViewOKInfo:)]) {
        [self.delegate pHomeFilterViewOKInfo:dic];
    }
    [self dismissView];
}
- (void)pHomeFilterAreaViewCancel {
    [self dismissView];
}
- (void)pHomeFilterBaseInfoViewOkWage:(NSString *)wage experience:(NSString *)experience education:(NSString *)education scale:(NSString *)scale finance:(NSString *)finance trade:(NSString *)trade {
    if (self.delegate && [self.delegate respondsToSelector:@selector(pHomeFilterViewBaseInfoOkWage:experience:education:scale:finance:trade:)]) {
        [self.delegate pHomeFilterViewBaseInfoOkWage:wage experience:experience education:education scale:scale finance:finance trade:trade];
    }
    [self dismissView];
}

@end
